package com.cx.zhshopping.ui.binding_adapter;

import androidx.databinding.BindingAdapter;
import androidx.viewpager.widget.ViewPager;

import com.cx.zhshopping.ui.adapter.FragAdapter;


public class ViewPagerBindingAdapter {

    @BindingAdapter(value = "viewPagerSetAdapter",requireAll = false)
    public static void ViewPagerSetAdapter(ViewPager viewPager, FragAdapter adapter){
        viewPager.setAdapter(adapter);
        viewPager.setCurrentItem(0);
        viewPager.setOffscreenPageLimit(4);
    }

    @BindingAdapter(value = "viewPagerListener",requireAll = false)
    public static void ViewPagerSelectedListener(ViewPager viewPager, ViewPager.OnPageChangeListener listener) {
        viewPager.addOnPageChangeListener(listener);
    }

    @BindingAdapter(value = {"viewPagerPosition"},requireAll = false)
    public static void selectPosition(ViewPager viewPager, int position){
        viewPager.setCurrentItem(position);
    }

}
